package edu.hunau.cxb19.oop.class28;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

import org.junit.Test;

/**
 *
 * @author hb
 *
 *         2020-04-07 16:18:20
 */
public class ChannelTest {

	@Test
	public void createFile() throws Exception {
		File file = new File(".\\nio\\a01.txt");
		try ( // 创建一个FileInputStream,以该输入流创建FileChannel
			  FileChannel inChannel = new FileInputStream(file).getChannel();
			  FileChannel outChannel = new FileOutputStream(".\\nio\\channel.txt").getChannel();
		) {
			//将inChannle数据全部映射成为ByteBuffer
			MappedByteBuffer buffer = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
			//将buffer中的数据全部输出
			outChannel.write(buffer);

		}

	}
}
